home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / uucosr10.arc / FSEL.C < prev    next >
C/C++ Source or Header  |  1991-05-25  |  2KB  |  71 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. /*
  6.  * function: fsel
  7.  * description:  Display the GEM file selector, including a prompt if
  8.  *               one is supplied. The path and default filename will
  9.  *               be shown, if supplied. Convert the user's input into
  10.  *               a complete filename and copy the result into the
  11.  *               supplied buffer.
  12.  *
  13.  * side effects: fsel remembers the previous values of inpath and default
  14.  *               filename and uses them if those args are NULL
  15.  * 
  16.  * returned value: 0 if [CANCEL], 1 if [OK]
  17.  *
  18.  * warning: this will not work under TOS before 1.4 unless you use
  19.  *          Ian Lepore's GEMFAST bindings to fake the fsel_exinput call.
  20.  */
  21.  
  22.  
  23. static char xpath[128], xinsel[14];
  24.  
  25. fsel(prompt, path, insel, filename)
  26.     char *prompt, /* message to user, or NULL */
  27.          *path,  /* initial path, or NULL */
  28.              *insel, /* initial filename, or NULL */
  29.              *filename;    /* 128-byte buffer for full selected name */
  30.     {
  31.     char *p;
  32.     int button;
  33.     if (!prompt)
  34.         prompt = "Please choose a file";
  35.     if (!path)
  36.         fullpath(xpath,"*.*");
  37.     else
  38.         fullpath(xpath,path);
  39.     if (insel)
  40.         strcpy(xinsel,insel);
  41.     strupr(xpath);
  42.     strupr(xinsel);
  43.     fsel_exinput(xpath,xinsel,&button,prompt);
  44.     if (xinsel[0] == '\0')
  45.         button = FALSE;    /* don't let user select a blank file */
  46.     strcpy(filename,xpath);
  47.     if (p = strrchr(filename,'\\'))
  48.         *++p = '\0';
  49.     else if (p = strrchr(filename,':'))
  50.         *++p = '\0';
  51.     strcat(filename,xinsel);
  52.     return button;
  53.     }
  54.  
  55. #if TESTVERSION
  56. #include <stdio.h>
  57. main()
  58.     {
  59.     int button;
  60.     char full_filename[128];
  61.     appl_init();
  62.     button = fsel("Hello there",NULL,"FUBAR.TOS",full_filename);
  63.     printf("\nSelected file = [%s]; button = %d\n", full_filename, button);
  64.     printf("RETURN to exit.\n");
  65.     getchar();
  66.     appl_exit();
  67.     }
  68.  
  69. #endif
  70.  
  71.